package com.example.orderService.controller;

import com.example.orderService.client.UsersClient;
import com.example.orderService.model.Orders;
import com.example.orderService.model.Users;
import com.example.orderService.service.IOrdersService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/orders")
public class OrdersController {
    IOrdersService usersService;
    UsersClient usersClient;

    public OrdersController(IOrdersService usersService, UsersClient usersClient) {
        this.usersService = usersService;
        this.usersClient = usersClient;
    }

    @RequestMapping(value = "getList", method = RequestMethod.GET)
    public List<Orders> update_account() {
        return  usersService.list();
    }

    @RequestMapping(value = "getById", method = RequestMethod.GET)
    public Orders getById(@RequestParam("id") Long id) {
        Orders byId = usersService.getById(id);
        Users users = usersClient.getById(byId.getUserId());
        byId.setUsers(users);
        return  byId;
    }

    @RequestMapping(value = "gets", method = RequestMethod.GET)
    public String gets() {
        return  "usersService.list()";
    }

}
